//
//  Notelist.m
//  Novels
//
//  Created by xshu2 on 3/9/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "NoteList.h"


@implementation NoteList

@synthesize theList;

-(void) DictionaryTest{
	
	//NSMutableDictionary 
	self.theList = [[NSMutableDictionary alloc] initWithCapacity:1];
	[self AddNewNote:@"FirstNote"];
	
	NSLog(@"%@", self.theList);
	[self DeleteNote:@"1Note"];	
	
	NSArray *keys = [self.theList allKeys];	
	// values in foreach loop
	for (NSString *key in keys) {
		NSLog(@"%@ is %@",key, [self.theList objectForKey:key]);
	}
}  //Xin Shu: test method, not necessary

//Xin Shu: since obeject has dictionary instance variable, init is needed for allocation, otherwise [self.theList setObject:newNote forKey:listname] won't work
-(void) init
{	
	
	self.theList = [[NSMutableDictionary alloc] initWithCapacity:1];
	[super init];
}

-(void) AddNewNote:(NSString *)listname

{
	
	NSString *noteContent = @"Intial Content";
	NSString *noteDate =[NSDate date];// @"2010/03/11";
	NSMutableDictionary *newNote=[[NSMutableDictionary alloc] init];
	
	[newNote setObject:noteContent forKey:@"Content"];	
	[newNote setObject:noteDate	forKey:@"Date"];
	NSLog(@"%@", newNote);		
	[self.theList setObject:newNote forKey:listname];
}


-(void) DeleteNote:(NSString *)listname

{
	[theList removeObjectForKey: listname];
	NSLog(@"%@", theList);
}

- (void)encodeWithCoder:(NSCoder *)coder {
    [super encodeWithCoder:coder];
    [coder encodeObject:theList forKey:@"theList"];
	
}

- (id)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    theList = [[coder decodeObjectForKey:@"theList"] retain];
    return self;
}


- (NSData*) serialize
{
    return [NSKeyedArchiver archivedDataWithRootObject:self];
}

@end

